package nl.science.uva.pico.operator;

import nl.science.uva.pico.Stack;
import nl.science.uva.pico.operand.Operand;

/** 
 * Skip transfers control to the next instruction 
 * 
 * @author Ivo van Dongen, Karel Pieterson
 * @version 1.0
 */
public class Store extends Operator {

	public Store(Stack stack) {
		super(stack, null, null);
	}

	/** 
	 * Store The store instruction stores the value e at stack location x 
	 * (x, of course, should be an integer constant).
	 *  
	 *  @throws IllegalStateException
     */
	@Override
	public void perform() {
		if(getStack().size() >= 2) {
			Integer address = getStack().pop().getIntegerValue();
			Operand value = getStack().pop();
			getStack().store(value, address);
		} else {
			throw new IllegalStateException(" Too few operands, Store needs 2 operands");
		}
	}

}
